/**
 * 
 */
package me.myachievements.web.tag;

import java.io.Serializable;
import java.util.Collection;

import me.myachievements.persistence.goal.Goal;
import me.myachievements.persistence.goal.GoalPersistenceManager;
import me.myachievements.persistence.tag.Tag;
import me.myachievements.persistence.tag.TagPersistenceManager;

import org.apache.wicket.markup.html.form.ChoiceRenderer;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.form.ListMultipleChoice;
import org.apache.wicket.model.CompoundPropertyModel;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.LoadableDetachableModel;
import org.apache.wicket.model.Model;
import org.apache.wicket.spring.injection.annot.SpringBean;

/**
 * @author besseym
 *
 */
public class GoalTagAddForm extends GoalTagForm {
	
	private ListMultipleChoice<Tag> tagListMultipleChoice;

	public GoalTagAddForm(String id, final Goal goal) {
		
		super(id, goal);
		
		ChoiceRenderer<Tag> renderer = new ChoiceRenderer<Tag>("value", "id");
		UnAssociatedTagsModel unAssociatedTagsModel = new UnAssociatedTagsModel(goal.getId());
		tagListMultipleChoice = new ListMultipleChoice<Tag>("tagList", unAssociatedTagsModel, renderer);
		add(tagListMultipleChoice);
	}
	
	@Override
	protected void onSubmit(){
		
		GoalTagFormModel tagGoalFormModel = this.getModelObject();
		this.getGoal().getTags().addAll(tagGoalFormModel.getTagList());
		
		this.tagListMultipleChoice.detach();
		
//		tagListMultipleChoice.getChoices().removeAll(tagGoalFormModel.getTagList());
		
		super.onSubmit();
	}

}
